package com.xxd.rpt2.controller

import com.xxd.rpt2.Entity.User
import com.xxd.rpt2.service.DepartmentService
import com.xxd.rpt2.service.UserService
import io.swagger.annotations.Api
import io.swagger.annotations.ApiImplicitParam
import io.swagger.annotations.ApiImplicitParams
import io.swagger.annotations.ApiOperation
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestMethod
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController

@Api(tags = "tags:测试",value = "value：测试")
@RestController
@RequestMapping("/testSwagger")
class TestSwagger {

    @Autowired
    UserService userService
    @Autowired
    DepartmentService departmentService

    @ApiOperation(value = "value:测试swagger",notes = "notes:备注")
    @ApiImplicitParams( value = [
            @ApiImplicitParam(name = "name", value = "用户名", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "id", value = "用户ID", dataType = "String", paramType = "query")
    ])
    @RequestMapping(value ="test",method = RequestMethod.GET)
    public String test(@RequestParam(name="name" ,required = false ) String name , @RequestParam(required = false) Integer id){

        [name:name ,id:id]
    }

    @RequestMapping(value ="test1",method = RequestMethod.GET)
    public String test1( ){
        [name:"name" ,id:"id"]
    }


    @RequestMapping(value = "getPageUser",method = [RequestMethod.POST,RequestMethod.GET])
    def getPageUser(@RequestParam(required = false,defaultValue = "管理") String name,
                    @RequestParam(required = false,defaultValue = "6") int deptId,
                    @RequestParam(defaultValue = "1") int page,
                    @RequestParam(defaultValue = "20") int pageSize){
        User user = new User(name:name,department: departmentService.getById(deptId)?:null)
        userService.findByPage(user,page,pageSize)
    }

    @RequestMapping(value = "getAllDepartment",method = [RequestMethod.POST,RequestMethod.GET])
    def getAllDepartment(){
        return departmentService.findAll()
    }
}
